package com.yunhe.assist.controller;

import com.yunhe.assist.domain.FeedbackReply;
import com.yunhe.assist.service.FeedbackReplyService;
import com.yunhe.assist.util.MyHeaderUtil;
import com.yunhe.common.model.ResultObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * @description feedback_reply
 * @author dlz
 * @date 2021-11-09
 */
@Api(value = "FeedbackReply", description = "feedback_reply维护", tags = {"Model_FeedbackReply"})
@RestController
@RequestMapping(value = "/feedbackReply")
public class FeedbackReplyController {

    @Autowired
    private FeedbackReplyService feedbackReplyService;
    @Autowired
    private MyHeaderUtil myHeaderUtil;

    /**
     * 后台进行回复，包括园区后台以及云和后台
     */
    @ApiOperation(value = "后台进行回复，包括园区后台以及云和后台", notes = "必填：feedbackId（反馈主表id），replyContent（回复内容）, replyName（回复人姓名）")
    @PostMapping("/byAdmin")
    public ResponseEntity byAdmin(@RequestBody FeedbackReply reply){
        reply.setReplyUserId(myHeaderUtil.getHeaderUser());
        feedbackReplyService.createFeedbackReply(reply);
        return new ResponseEntity<>(new ResultObject(),HttpStatus.OK);
    }

    /**
     * 移动端进行回复 包括小程序以及app
     */
    @ApiOperation(value = "移动端进行回复 包括小程序以及app", notes = "必填：feedbackId（反馈主表id），feedbackUserId（回复人id），replyContent（回复内容）, replyName（回复人姓名）")
    @PostMapping("/byMobile")
    public ResponseEntity byMobile(@RequestBody FeedbackReply reply){
        Assert.isTrue(Objects.nonNull(reply.getFeedbackUserId()), "回复人id不能为空");
        feedbackReplyService.createFeedbackReply(reply);
        return new ResponseEntity<>(new ResultObject(),HttpStatus.OK);
    }

}